package com.fjnu.test;

import static org.junit.Assert.*;

import java.sql.SQLException;
import java.util.List;

import javax.sql.DataSource;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.fjnu.dao.ImainInstrumentDao;
import com.fjnu.dao.impl.mainInstrumentDao;
import com.fjnu.entities.Administrator;
import com.fjnu.entities.MainInstrument;

public class test {
	private ApplicationContext ctx =null;
	@Autowired
	private ImainInstrumentDao mainInstrumentDao;
	@Test
	public void testDataSource() throws SQLException{
		ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
		System.out.println(ctx);
		DataSource ds=ctx.getBean(DataSource.class);
		System.out.println(ds.getConnection().toString());
		SessionFactory sf=ctx.getBean(SessionFactory.class);
		System.out.println(sf);
		Session session=sf.openSession();
		Transaction tx=session.beginTransaction();
		//Administrator ad=new Administrator();
		//ad.setPerson_name("skkk");
		MainInstrument mi=new MainInstrument();
		mi.setInstrumentName("李四");
		//mainInstrumentDao mainDao=new mainInstrumentDao();
		mainInstrumentDao.addInstrument(mi);
		tx.commit();
		session.close();
		
	}
	@Test
	public void testIns(){
		List<MainInstrument> list=mainInstrumentDao.findManyInstrument("condition", 1, 1);
		System.out.println(list);
	}

}
